package com.hiwhitley.easy.day26;

/**
 * Created by hiwhitley on 2016/10/24.
 */
public class SortColors_75 {
    public void sortColors(int[] nums) {
        if (nums == null || nums.length == 0)
            return;
        int count1 = 0;
        int sum = 0;
        for (int i : nums) {
            if (i == 1)
                count1++;
            sum += i;
        }

        int count2 = (sum - count1) / 2;
        int count0 = nums.length - count1 - count2;

        for (int i = 0; i < count0; i++) {
            nums[i] = 0;
        }
        for (int i = count0; i < count1 + count0; i++) {
            nums[i] = 1;
        }
        for (int i = count1 + count0; i < nums.length; i++) {
            nums[i] = 2;
        }
    }

    public static void main(String[] args) {
        SortColors_75 main = new SortColors_75();
        main.sortColors(new int[]{2, 1, 0, 0, 1});
    }
}
